<template>
  <div class="proDialog">
    <el-dialog title="选择设备" :visible.sync="visible" width="800px" z-index="1500" append-to-body @close="toCancelBox">
      <el-form class="formList" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
        label-width="80px" style="padding-top: 0">


        <el-form-item label="设备名称" prop="deviceName">
          <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable size="small" />
        </el-form-item>




        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>

      <el-table border ref="indexTable" :data="infoList" tooltip-effect="dark" style="width: 100%"
        @selection-change="handleSelectionChange" :row-key="bindRowKeys">
        <el-table-column type="selection" align="center" :reserve-selection="true">
        </el-table-column>

        <el-table-column prop="deviceImage" label="图片" align="center" width="100">
          <template slot-scope="scope">
            <el-image v-if="
              scope.row.deviceImage != null && scope.row.deviceImage != ''
            " slot="reference" :src="scope.row.deviceImage" class="image-rows"
              :preview-src-list="[scope.row.deviceImage]">
            </el-image>
          </template>
        </el-table-column>
        <el-table-column prop="deviceName" label="设备名称" width="120" align="left">
        </el-table-column>
        <el-table-column prop="deviceBrand" label="设备品牌" align="center"></el-table-column>
        <el-table-column prop="isLock" label="是否独占设备" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.isLock === '1' ? '独占':'不独占'}}</span>
          </template>
        </el-table-column>

      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" :page-sizes="pageSizess" />

      <div style="display:flex; justify-content: flex-end;">
        <el-button @click="determine" type="primary">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>

import {
listByItemId
} from "@/api/service/item"
export default {
props: {
flag: {
type: Boolean,
},
itemUid: {
type: Number,
}
},
watch: {
flag(val) { },
},
data() {
return {
// 显示搜索条件
showSearch: true,
datas: null,
selectedDatas: [],
pageSizess: [5, 10, 15, 20, 25, 30, 50],
// 商品信息表格数据
infoList: [],
// indexTable: [],
infoListHistory: [],
multipleSelection: [],
total: 0,
queryParams: {
pageNum: 1,
pageSize: 5,
deviceName: null,
itemId: this.itemUid,
},
visible: false,
categoryOptions: []
};
},
created() {
this.visible = this.flag;
this.getList();

},
methods: {
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
toCancelBox() {
this.visible = false;
this.$emit("toCloseBox", false);
},
//回显选中
greet(selectedData) {
this.selectedDatas = selectedData;
this.selectedDatas.forEach((item) => {
this.$refs.indexTable.toggleRowSelection(item, true);
});
},
bindRowKeys(row) {
return row.deviceId;
},
handleSelectionChange(val) {
this.datas = this.multipleSelection;
this.multipleSelection = val
console.log(this.datas);
console.log(this.multipleSelection);
if (this.datas.length > 0) {
for (let i = 0; i < this.datas.length; i++) {
for (let k = 0; k < this.multipleSelection.length; k++) {
if (this.datas[i].deviceId == this.multipleSelection[k].deviceId) {
this.multipleSelection[k] = this.datas[i]
}
}
}
}
},
/** 确定选择商品 */
determine() {
this.$emit("multipleSelection", this.multipleSelection);
this.infoList.forEach((item) => {
this.$refs.indexTable.toggleRowSelection(item, false);
});
this.$forceUpdate();
this.open = false;
},
/** 查询商品信息列表 */
getList() {
listByItemId(this.queryParams).then((response) => {
this.infoList = response.rows;
this.total = response.total;
this.loading = false;
});
},
},
};
</script>
<style scoped>
.determine {
  position: relative;
  color: #fff;
}

.pagination-container {
  position: relative;
}

.image-rows {
  width: 80px;
  height: 80px;
}
</style>
